package com.chinairi.mall.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chinairi.common.utils.ResponseUtil;
import com.chinairi.mall.service.IOrderCommodityTrackAlarmService;
import com.chinairi.mall.service.modelobject.OCTAForSPMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chinairi.common.controller.BaseController;

import java.io.IOException;
import java.util.List;

/**
 * <p>F
 * 预警表 前端控制器
 * </p>
 *
 * @author Webgasd
 * @since 2020-08-19
 */
@RestController
@RequestMapping("/order-commodity-track-alarm")
public class OrderCommodityTrackAlarmController extends BaseController {
    @Autowired
    private IOrderCommodityTrackAlarmService iOrderCommodityTrackAlarmService;

    @PostMapping("/receiveAlarmFromServiceProvider")
    @ResponseBody
    public void receiveAlarmFromServiceProvider(@RequestBody String json) throws IOException {
        JSONObject jsonObject = JSON.parseObject(json);
        JSONArray jsonArray = jsonObject.getJSONArray("octaForSPMOList");
        List<OCTAForSPMO> list = JSONObject.parseArray(jsonArray.toJSONString(), OCTAForSPMO.class);
        iOrderCommodityTrackAlarmService.updateByServiceProviderPlan(list);
        ResponseUtil.showMessage("success", "更新成功", null);
    }
}
